/*
 * Copyright ShangHai ECLUB Information Technology Co.,Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at

 * http://www.apache.org/licenses/LICENSE-2.0

 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 */

package com.eclub.emotion.rootstone.server.http;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;

import org.jboss.netty.buffer.ChannelBuffer;
import org.jboss.netty.handler.codec.http.HttpMethod;
import org.jboss.netty.handler.codec.http.HttpVersion;

import com.eclub.emotion.rootstone.server.http.mapping.ServiceMethodHandler;

/**
 * HTTP Request
 * @author   jun.yang, Wincor Nixdorf International GmbH
 */
public class HttpRequest  implements org.jboss.netty.handler.codec.http.HttpRequest{
	
	private String fromIP;
	private String toIP;
	private byte[] content;
	private Map<String, String> headers = new HashMap<String, String>();
	private Map<String, List<String>> _headers;
	private Map<String,List<String>>  queryParams;
	private ServiceMethodHandler serviceMethodHandler;
	
	
	private final org.jboss.netty.handler.codec.http.HttpRequest httpRequest; 
	
	/**
	 * Default constructor 
	 * @param httpRequest
	 */
	public HttpRequest(org.jboss.netty.handler.codec.http.HttpRequest httpRequest){
		this.httpRequest = httpRequest;
	}
	
	/**
	 * get values of header , it return Map<String,List<String>> data type.
	 * key:name of header, value value collection of header.
	 * @return Map<String,List<String>>
	 */
	public Map<String,List<String>> getValuesofHeader(){
		return _headers;
	}
	
	public void setValuesOfHeader(Map<String,List<String>> valuesOfHeader){
		this._headers = valuesOfHeader;
	}
	
	
	public Map<String, List<String>> getQueryParams() {
		return queryParams;
	}

	public void setQueryParams(Map<String, List<String>> queryParams) {
		this.queryParams = queryParams;
	}

	public String getQueryString(String key) {
		return null;
	}


	public String getFromIP() {
		return fromIP;
	}

	

	public void setFromIP(String fromIP) {
		this.fromIP = fromIP;
	}

	public void setHeaders(Map<String, String> headers) {
		this.headers = headers;
	}

	public void setUri(String uri) {
		httpRequest.setUri(uri);
	}

	public String getUri() {
		return httpRequest.getUri();
	}

	public void setContent(byte[] content) {
		this.content = content;
	}
	

	public void setToIP(String toIP) {
		this.toIP = toIP;
	}

	public String getToIP() {
		return toIP;
	}

	@Override
	public String getHeader(String name) {
		return httpRequest.getHeader(name);
	}

	@Override
	public List<String> getHeaders(String name) {
		return httpRequest.getHeaders(name);
	}

	@Override
	public List<Entry<String, String>> getHeaders() {
		return httpRequest.getHeaders();
	}

	@Override
	public boolean containsHeader(String name) {
		return httpRequest.containsHeader(name);
	}

	@Override
	public Set<String> getHeaderNames() {
		return httpRequest.getHeaderNames();
	}

	@Override
	public HttpVersion getProtocolVersion() {
		return httpRequest.getProtocolVersion();
	}

	@Override
	public void setProtocolVersion(HttpVersion version) {
		httpRequest.setProtocolVersion(version);
	}

	@Override
	public ChannelBuffer getContent() {
		return httpRequest.getContent();
	}

	@Override
	public void setContent(ChannelBuffer content) {
		httpRequest.setContent(content);
	}

	@Override
	public void addHeader(String name, Object value) {
		httpRequest.addHeader(name, value);
	}

	@Override
	public void setHeader(String name, Object value) {
		httpRequest.setHeader(name, value);
	}

	@Override
	public void setHeader(String name, Iterable<?> values) {
		httpRequest.setHeader(name, values);
	}

	@Override
	public void removeHeader(String name) {
		httpRequest.removeHeader(name);
	}

	@Override
	public void clearHeaders() {
		httpRequest.clearHeaders();
	}
	
	
	public ServiceMethodHandler getServiceMethodHandler() {
		return serviceMethodHandler;
	}

	public void setServiceMethodHandler(ServiceMethodHandler serviceMethodHandler) {
		this.serviceMethodHandler = serviceMethodHandler;
	}

	@Override
	public long getContentLength() {
		return httpRequest.getContentLength();
	}

	@Override
	public long getContentLength(long defaultValue) {
		return httpRequest.getContentLength(defaultValue);
	}

	@Override
	public boolean isChunked() {
		return httpRequest.isChunked();
	}

	@Override
	public void setChunked(boolean chunked) {
		httpRequest.setChunked(chunked);
	}

	@Override
	public boolean isKeepAlive() {
		return httpRequest.isKeepAlive();
	}

	@Override
	public HttpMethod getMethod() {
		return httpRequest.getMethod();
	}

	@Override
	public void setMethod(HttpMethod method) {
		httpRequest.setMethod(method);
	}
}
